package com.itmei.sms.controller;
import cn.hutool.core.date.DateUtil;

import com.itmei.sms.entity.SmsTemplateConfig;
import com.itmei.sms.enums.SmsSceneEnum;
import com.itmei.sms.enums.SmsSendSourceEnum;
import com.itmei.sms.enums.SmsSupplierEnum;
import com.itmei.sms.service.SmsServiec;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author itmei
 * @Date 2023/2/7 14:32
 * @description: 短信控制层
 * @Title: SmsController
 * @Package com.itmei.sms.controller
 */
@RestController
public class SmsController {
    @Resource
    private SmsServiec smsServiec;

    @GetMapping("sys/sendSms")
    public ResponseEntity<String> sendSms(String phone){
        System.out.println("发送");
        SmsTemplateConfig config = new SmsTemplateConfig();
        config.setSceneEnum(SmsSceneEnum.APPOINTMENT_SUCCESS.getCode());
        config.setSupplierEnum(SmsSupplierEnum.ALIYUN_SMS.getCode());
        config.setSourceEnum(SmsSendSourceEnum.PC.getCode());
        Map<String, Object> params = new HashMap<>();
        //传递对应模板的参数信息
        params.put("name","itmei");
        params.put("time", DateUtil.now());
        config.setTemplateParam(params);
        smsServiec.sendSms(phone, config, true);
        return ResponseEntity.ok("成功！");
    }
}
